<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'资源添加', styles:'bootstrap,font-awesome,animate,style,dtvalidate,layer,layui,chosen,bootstrap-table'}){%>
    <style type="text/css">
        body{padding-top:10px;}
        *{margin:0;padding:0;list-style-type:none;}
        a,img{border:0;}
        .demo h2{font-size:16px;color:#3366cc;height:30px;}
        .demo li{float:left;}
        .has-no{color:#3366cc;}
        .has-success{color: #1ab394;}
        .has-warning{color: #f8ac59;}
        .has-error{color: #ed5565;}
        .has-receive{color: #9E792E;}
        .remark {
            width: 100%; /*自动适应父布局宽度*/
            overflow: auto;
            word-break: break-all;
        }
    </style>
    <%}%>
</head>

<body>
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins" style="margin-bottom: 0px;">
                <div class="ibox-content" style="padding:15px 20px 0px 20px;">
                    <form id="search-form" role="form" class="form-horizontal" autocomplete="off">
                        <div class="form-group">
                            <label class="control-label col-sm-1">期间:</label>
                            <div class="col-sm-2">
                                <input type="text" id="period" name="period" placeholder="请选择期间" class="form-control">
                            </div>
                            <label class="control-label col-sm-1">主体:</label>
                            <div class="col-sm-2">
                                <select  name="shopName" id="shopName" class="form-control">
                                    <option value="">全部</option>
                                    <%for(var dict in shop){%>
                                    <option value="${dict.detailName}">${dict.detailName}</option>
                                    <%}%>
                                </select>
                            </div>
                            <label class="control-label col-sm-1">店铺:</label>
                            <div class="col-sm-2">
                                <select  name="brandName" id="brandName" class="form-control">
                                    <option value="">全部</option>
                                    <%for(var dict in brand){%>
                                    <option value="${dict.detailName}">${dict.detailName}</option>
                                    <%}%>
                                </select>
                            </div>
                            <label class="control-label col-sm-1">国家:</label>
                            <div class="col-sm-2">
                                <select name="countryName" id="countryName" class="form-control">
                                    <option value="">全部</option>
                                    <%for(var dict in country){%>
                                    <option value="${dict.detailName}">${dict.detailName}</option>
                                    <%}%>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-sm-1">费用类型:</label>
                            <div class="col-sm-2">
                                <select id="feeType" name="feeType" class="form-control">
                                    <option value="">请选择</option>
                                    <%for(var dict in feeType){%>
                                    <option value="${dict.feeType}">${dict.feeType}</option>
                                    <%}%>
                                </select>
                            </div>
                            <label class="control-label col-sm-1">Listing:</label>
                            <div class="col-sm-2">
                                <select id="listing" name="listing" xm-select="listing" xm-select-radio xm-select-search>
                                    <option value=""></option>
                                    <%for(var dict in listing){%>
                                    <option value="${dict.listingName}"  >${dict.listingName}</option>
                                    <%}%>
                                </select>
                                <input type="hidden" name="listingName" id="listingName">
                            </div>
                            <label class="control-label col-sm-1">SKU:</label>
                            <div class="col-sm-2">
                                <input type="text" id="sku" name="sku"  class="form-control">
                            </div>
                            <a class="search-btn btn btn-success" style="margin-bottom: 0px;">生成源数据</a>
                        </div>
                    </form>
                </div>
            </div>
            <!-- START 数据表格 -->
            <table id="portTable"
                   data-toolbar="#toolbar"
                   data-side-pagination="server"
                   data-pagination="true"
                   data-resizable="true"
                   data-url="/sea/finance/vtFeeOriginally/findByCnd.do"
                   data-page-size="15"
                   class="table table-striped table-hover"
            >
            </table>
        </div>
    </div>
    <!-- END 数据表格 -->
</div>


<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,dtvalidate,dtvalidate-lang-zh_cn,bootstrap-table-zh-CN,laydate,layer,chosen,chosen-demo,layui,upload'}){}%>
<script>
    var ind=null;

    laydate.render({
        elem: '#period',
        type: 'month'
        ,trigger: 'click'
    });



    var $portTable = $('#portTable');
    $(function(){
        //START 表格配置
        $portTable.bootstrapTable({
            columns: [
                {
                    field: 'state',
                    checkbox: true,
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '账期',
                    field: 'period',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '主体',
                    field: 'shopName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '店铺',
                    field: 'brandName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '国家',
                    field: 'countryName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '费用类型',
                    field: 'feeType',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: 'Listing',
                    field: 'listingName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: 'sku',
                    field: 'sku',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '文件',
                    field: 'fileUrl',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        if(null!=v && v!=''){
                            var result='<button  class="download-btn layui-btn  layui-btn-sm"  style="margin-top: -6px;margin-left: -4px">';
                            result+='<i class="fa fa-download" aria-hidden="true"></i> <a href="'+v+'" download style="color: white">下载附件</a>';
                            result+='</button>';
                            return result;
                        }else{
                            return '';
                        }
                    }
                },
                {
                    title: '数量',
                    field: 'totalNumber',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        if(null!=v && v!='' && v>800000){
                            var result=v;
                            result+='<br />';
                            result+='* 数量已超80万 请分批导出';
                            return result;
                        }
                    }
                },
                {
                    title: '状态',
                    field: 'flag',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v, r) {
                        switch (v) {
                            case 0:
                                return '<label class="control-label has-no"><i class="fa fa-circle" aria-hidden="true"></i> 未处理</label>';
                                break;
                            case 1:
                                return '<label class="control-label has-success"><i class="fa fa-circle" aria-hidden="true"></i> 处理数据中</label>';
                                break;
                            case 2:
                                return '<label class="control- label has-error"><i class="fa fa-circle" aria-hidden="true"></i> 处理失败,请联系管理员</label>';
                                break;
                            case 3:
                                return '<label class="control-label has-success"><i class="fa fa-circle" aria-hidden="true"></i> 处理成功</label>';
                                break;
                        }
                    }
                },
                {
                    title: '创建时间',
                    field: 'createTime',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    field: 'operate',
                    title: '操作',
                    align: 'center',
                    valign: 'middle',
                    formatter: optFormatter
                }
            ],
            onLoadSuccess : function(){

            }
        });
        //操作菜单
    });

    function optFormatter(value,row){
        var content= '';

        return content;
    }

    $('.search-btn').on('click',function(){
        var listing = formSelects.value('listing', 'nameStr'); // 获取值并去除首尾空格
        var sku = $("#sku").val();
        if (null != listing && listing !='') {
            $("#listingName").val(formSelects.value('listing', 'nameStr'));
        } else {
            $("#listingName").val("");
        }
        var shopName=$("#shopName").val();
        if(shopName=='' || null==shopName){
            layer.msg('请先选择主体！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
            return;
        }
        var period=$("#period").val();
        if(period==''){
            layer.msg('请先选择日期！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
            return;
        }


        var feeType=$("#feeType").val();
        if(feeType=='' || null==feeType){
            layer.msg('请先选择费用类型！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
            return;
        }
        var index= layer.load(2, { //icon支持传入0-2
            shade: [0.1, '#fff'], //0.5透明度的灰色背景
            content: '正在生成源数据,请稍后...',
            success: function (layero) {
                layero.find('.layui-layer-content').css({
                    'padding-top': '39px',
                    'margin-left': '-50px',
                    'width': '300px',
                    'font-color': 'red',
                    'font-size': '20px'
                });
            }
        });
        $.post('/sea/finance/vtFeeOriginally/save.do',$('#search-form').serialize(),function(data){
            if( data.ok ){
                layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']}, function(){
                    $portTable.bootstrapTable('refresh');
                    layer.close(index);
                });
            }else{
                parent.layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
                layer.close(index);
            }
        });

    });

    $('.test-btn').on('click',function(){

        $.post('/sea/finance/vtFeeOriginally/test.do',$('#search-form').serialize(),function(data){
            if( data.ok ){
                layer.msg(data.msg,{icon:1,time:1500,shade: [0.8, '#393D49']}, function(){
                    $portTable.bootstrapTable('refresh');
                    // layer.close(parent.layer.getFrameIndex(window.name)); //关闭弹窗
                    layer.close(index);
                });
            }else{
                parent.layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
                layer.close(index);
            }
        });

    });

</script>
</body>
</html>
